package logic

import (
	"context"
	"everyone/B/rpc_B/model/mysql"

	"everyone/B/rpc_B/everyone"
	"everyone/B/rpc_B/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsListLogic {
	return &GoodsListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodsListLogic) GoodsList(in *everyone.GoodsListRequest) (*everyone.GoodsListResponse, error) {
	// todo: add your logic here and delete this line
	g := mysql.Goods{}
	list, err := g.Find(in.GoodsStatue, in.Page, in.PageSize)
	if err != nil {
		logx.Error("商品查询失败")
	}
	if g.GoodsStatue == 2 {
		logx.Error("审核不通过")
	}
	var goods []*everyone.GoodsItem
	for _, s := range list {
		goods = append(goods, &everyone.GoodsItem{
			GoodsTitle:  s.GoodsTitle,
			GoodsNum:    s.GoodsNum,
			GoodsImage:  s.GoodsImage,
			GoodsPrice:  float32(s.GoodsPrice),
			GoodsLike:   s.GoodsLike,
			GoodsStatue: s.GoodsStatue,
		})
	}
	return &everyone.GoodsListResponse{
		GoodsList: goods,
	}, nil
}
